package com.engine;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class ReadConfig {
	String fileprops="ticketsq.props";
	static Properties props;
	static ReadConfig INSTANCE=null;
	
	private static void createInstance(String fileprops) throws FileNotFoundException, IOException
	{
		INSTANCE=new ReadConfig(fileprops);
	}
	public synchronized static ReadConfig getInstance(String fileprops) throws FileNotFoundException, IOException
	{
		if(INSTANCE==null) createInstance(fileprops);
		return INSTANCE;
	}
	public synchronized static void removeInstance()
	{
		INSTANCE=null;
	}
	private ReadConfig(String fileprops) throws FileNotFoundException, IOException
	{
		if(fileprops!=null)
			this.fileprops = fileprops;
		props=new Properties();
		props.load(new FileInputStream(this.fileprops));
	}
	
	public static String GET(String key)
	{
		return props.getProperty(key);
	}
	
	public static int toInt(String key)
	{
		try
		{
			return Integer.parseInt(props.getProperty(key));
		}
		catch(Exception es){
			return -1;
		}
	}
}
